<script setup lang="ts">
// 获取category id 下产品
import { onMounted, ref } from 'vue'
import { getGoodsList } from '@/api'
import { useRoute } from 'vue-router'

const route = useRoute()

// tabs 数据
const categoryId = ref(0)
const goodsList = ref([])

const getPageData = async () => {
  const data = await getGoodsList({ pid: categoryId.value, })
  goodsList.value = data
}

onMounted(() => {
  if (route.query?.id) {
    if (Number(route.query.id)) {
      categoryId.value = Number(route.query.id) ?? 0
    }
    getPageData()
  }
})
</script>

<template>
  <div class="layout-container">
    <el-row :gutter="20">
      <el-col :span="6" v-for="item in goodsList" :key="item.id" class="mb-20">
        <el-card>
          <!--          <template #header>{{item.name}}</template>-->
          <img :src="item.cover_image" style="width: 100%" />
          <template #footer>
            <h3 class="title">{{ item.title }}</h3>
            <p class="intro">{{item.intro}}</p>
          </template>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<style lang="scss" scoped>
.layout-container {
  min-height: 80vh;
}
.title{
  font-size: 18px;
}

.intro{
  color: #666;
}
</style>
